/**
*      author: Y_Yao
*      created: 2024-09-14 22:23:30
**/

#include<bits/stdc++.h>
#include<unordered_map>

using namespace std;
const int N = 2e5 + 9;
vector<pair<int,int>> nums(N);
using LL = long long;


void solve()
{
    int n;
    cin>>n;
    unordered_map<int,int> row;
    unordered_map<int,int> line;
    unordered_map<int,int> up;
    unordered_map<int,int> down;
    for(int i = 0;i < n;i++)
    {
        cin >> nums[i].first >> nums[i].second;
        row[nums[i].first]++;
        line[nums[i].second]++;
        up[nums[i].first - nums[i].second + n]++;
        down[nums[i].first + nums[i].second]++;
    }
    long long ret = 0;
    for(int i =0;i < n;i++)
    {
        if(row[nums[i].first] > 1 && line[nums[i].second] > 1)
        {
            ret += (row[nums[i].first] - 1) * (line[nums[i].second] - 1);
        }
        if(up[nums[i].first - nums[i].second + n] > 1 && down[nums[i].first + nums[i].second] > 1);
        {
            ret += (up[nums[i].first - nums[i].second + n] - 1) * (down[nums[i].first + nums[i].second] - 1);
        }
    }
    cout<<ret<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t =0;
    cin >> t;
    //t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}